﻿/***********************************************************************
 * <copyright file="Mapper.cs" company="BUCA JSC">
 * -->    Copyright (C) statement. All right reserved
 * </copyright>
 * 
 * Created:  Nguyen Chi Binh
 * Email:    nguyentribinh@live.com
 * Website:
 * Create Date: Friday, April 11, 2014
 * Usage: 
 * 
 * RevisionHistory: 
 * Date         Author               Description 
 * 
 * ************************************************************************/

using System.Collections.Generic;
using System.Linq;
using DXWebApplication.NewsServiceReference;

namespace DXWebApplication.Areas.Administrators.Models.News
{
    /// <summary>
    /// Mapper class
    /// </summary>
    public static class Mapper
    {
        #region NewsLog
        /// <summary>
        /// Froms the model.
        /// </summary>
        /// <param name="obj">The obj.</param>
        /// <returns></returns>
        public static NewsLogDto FromModel(this NewsLogModel obj)
        {            
            if (obj == null) return null;
            return new NewsLogDto
            {
                Id = obj.Id,
                Title = obj.Title,
                Content = obj.Content,
                IP = obj.Ip,
                Location = obj.Location,
                Device = obj.Device,
                CreatedBy = obj.CreatedBy,
                CreatedDate = obj.CreatedDate,
                Type = obj.Type
            };
        }

        /// <summary>
        /// To the model.
        /// </summary>
        /// <param name="obj">The obj.</param>
        /// <returns></returns>
        public static NewsLogModel ToModel(this NewsLogDto obj)
        {
            if (obj == null) return null;

            return new NewsLogModel
            {
                Id = obj.Id,
                Title = obj.Title,
                Content = obj.Content,
                Ip = obj.IP,
                Location = obj.Location,
                Device = obj.Device,
                CreatedBy = obj.CreatedBy,
                CreatedDate = obj.CreatedDate,
                Type = obj.Type
            };
        }

        /// <summary>
        /// To the model.
        /// </summary>
        /// <param name="dtos">The dtos.</param>
        /// <returns></returns>
        public static List<NewsLogModel> ToModel(this List<NewsLogDto> dtos)
        {
            return dtos == null ? null : dtos.Select(item => item.ToModel()).ToList();
        }

        #endregion
    }
}